package com.bdqn.bookshop.controller.admin;

import com.bdqn.bookshop.common.BookConstants;
import com.bdqn.bookshop.entity.AdminUser;
import com.bdqn.bookshop.service.AdminUserService;
import com.bdqn.bookshop.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author : 罗若然[LUO_RUO_RAN]
 * @date : 2020-07-25 16:14
 **/
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    public AdminUserService adminUserService;

    @PostMapping("/login")
    public Result login(AdminUser user, HttpSession session){
        Result result = adminUserService.getAdminUser(user);
        if (result.isSuccess()){
            session.setAttribute(BookConstants.LOGIN_ADMIN_USER,result.getData());
        }
        return result;
    }


    @RequestMapping("/isPasCorrect")
    public Result isPasCorrect(Integer id,String pass){
        return adminUserService.isPasCorrect(id,pass);
    }

    @RequestMapping("/updateName")
    public Result updateName(AdminUser adminUser){
        return adminUserService.updateName(adminUser);
    }

    @RequestMapping("/updatePass")
    public Result updatePass(Integer id,String orPass,String newPass,String confirmPass){
        return adminUserService.updatePass(id,orPass,newPass,confirmPass);
    }

}
